<?php
// 连接数据库
include 'connect.php';
// 查询员工信息
$sql = "SELECT * FROM employees";
$result = mysqli_query($conn, $sql);
?>
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>员工信息</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.datatables.net/2.1.8/css/dataTables.bootstrap5.css">
    <script src="https://code.jquery.com/jquery-3.7.1.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.datatables.net/2.1.8/js/dataTables.js"></script>
    <script src="https://cdn.datatables.net/2.1.8/js/dataTables.bootstrap5.js"></script>
</head>
<body>
<?php include 'nav.php'; ?>
<div class="container mt-5">
    <table id="employeeTable" class="table table-striped">
        <thead>
        <tr>
            <th>部门</th>
            <th>姓名</th>
            <th>性别</th>
            <th>电话</th>
            <th>入职日期</th>
            <th>状态</th>
            <th>上操作</th>
        </tr>
        </thead>
        <tbody>
        <?php while ($row = mysqli_fetch_assoc($result)) { ?>
            <tr>
                <td><?php echo $row['department']; ?></td>
                <td><?php echo $row['name']; ?></td>
                <td><?php echo $row['gender']; ?></td>
                <td><?php echo $row['tel']; ?></td>
                <td><?php echo $row['hire_date']; ?></td>
                <td> <?php
                    if ($row['status'] == '在职') {
                        echo '<span class="mb-2 bg-success text-white">' . $row['status'] . '</span>';
                    } else {
                        echo '<span class="mb-2 bg-danger  text-white">' . $row['status'] . '</span>';
                    }
                    ?></td>
                <td>
                    <a href="edit_employee.php?id=<?php echo $row['id']; ?>" class="btn btn-sm btn-primary">编辑</a>
                    <a href="turnover_employee.php?id=<?php echo $row['id']; ?>"  class="btn btn-sm btn-warning <?php if ($row['status'] == '离职') {echo 'disable';}?>">离职</a>
                    <a href="delete_employee.php?id=<?php echo $row['id']; ?>" class="btn btn-sm btn-danger">删除</a>
                </td>
            </tr>
        <?php } ?>
        </tbody>
    </table>
</div>
<script>
    $(document).ready(function () {
        $('#employeeTable').DataTable({
            language: {
                url: '//cdn.datatables.net/plug-ins/2.1.8/i18n/zh.json',
            }
        });
    });
</script>
</body>
</html>